package cn.xiaoxiang.basic.controller;

import cn.xiaoxiang.basic.dto.EmailDto;
import cn.xiaoxiang.basic.dto.SmsCodeDto;
import cn.xiaoxiang.basic.service.VerifyCodeService;
import cn.xiaoxiang.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {
    @Autowired
    private VerifyCodeService verifyCodeService;

    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult graph(@PathVariable("imageCodeKey") String redisKey) throws IOException {
        String base64Graph =  verifyCodeService.graph(redisKey);
        return AjaxResult.me().success(base64Graph);
    }

   @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody SmsCodeDto dto)  {
         verifyCodeService.smsCode(dto);
        return AjaxResult.me().success();
    }
    @PostMapping("/email")
    public AjaxResult email(@RequestBody EmailDto emailDto)  {
        verifyCodeService.email(emailDto);
        return AjaxResult.me().success();
    }

}
